// router.js
import {RouterMount,createRouter} from 'uni-simple-router';

const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,  
	routes: [
		{
		  path: '/pages/index/index',
		  name: 'index'
		},
		{
		  path: '/pages/login/login',
		  name: 'login'
		},
		...ROUTES]
});
//全局路由前置守卫

//注册路由白名单
const whiteList = ['/pages/login/login']
 //全局路由前置守卫
router.beforeEach(async (to, from, next) => {
	 // 获取base
	 const lifeData = uni.getStorageSync('lifeData');
	console.log(to,'这里是路由守卫');
		
	 if (whiteList.includes(to.path)) {
		// 当前路由在白名单中，允许访问
		next()
	
	  }else{
		  if(!lifeData.userInfo || lifeData.userInfo.fanstoken==undefined || !lifeData.userInfo.fanstoken){
			uni.setStorageSync('backurl', to.fullPath);
			 next({name:'login'})
			 
		  }else{
			    next(); 

		  }
		  
	  }

});
// 全局路由后置守卫
router.afterEach((to, from) => {
    console.log('跳转结束,后置守卫')
})

export {
	router,
	RouterMount
}